package org.lhl;

import com.sun.jna.Native;
import com.sun.jna.NativeLibrary;

import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;

import javafx.application.Application;
import javafx.stage.Stage;

public class Main extends Application {

    public static JnaLibrary INSTANCE;

    @Override
    public void start(Stage primaryStage) throws Exception {
        new Start().init(primaryStage);
    }

    public static void main(String[] args) {
        launch(args);
    }

    static {
        try {

            // getClass().getClassLoader().getResourceAsStream(arg0);
            // System.out.println("MainTest.class.getClass()"+MainTest.class.getClass().toString());
            InputStream in = Main.class.getResourceAsStream("/crypt");   //dll文件位置
            if (in == null) {
                System.err.println("输入流为空");
            }
            String filePath = System.getProperty("user.dir") + File.separator + "crypt.dll";
            File dll = new File(filePath);
            FileOutputStream out = new FileOutputStream(dll);   //缓存dll位置
            int i;
            byte[] buf = new byte[1024];
            try {
                while ((i = in.read(buf)) != -1) {
                    out.write(buf, 0, i);
                }
            } finally {
                in.close();
                out.close();
            }
            INSTANCE = Native.load(dll.getAbsolutePath(), JnaLibrary.class);
            System.out.println(dll.delete());
        } catch (Exception e) {
            e.printStackTrace();
            System.err.println("load jni error!");
        }
    }

}
